package com.assistant.codegen.modules.gen.domain;

import com.assistant.codegen.modules.model.domain.Model;
import com.assistant.codegen.modules.model.domain.Project;
import com.assistant.codegen.modules.model.domain.column.ModelColumn;
import com.assistant.util.StringUtils;
import lombok.Getter;

import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;

public class Context {

    @Getter
    private final Map<String, Object> value = new HashMap<>();

    public Context(CodeGenConfigurationProperties context, Model model) {
        final Project project = model.getProject();
        value.put("basePath", context.getBasePath());
        value.put("packageName", project.getPackageName());
        value.put("packagePath", project.getPackageName().replace(".", "/"));
        value.put("moduleName", model.getModuleName());
        value.put("subModuleName", model.getSubModuleName());
        value.put("domainName", model.getDomainName());
        value.put("modelName", model.getName());
        value.put("className", model.getDomainName());
        value.put("ClassName", StringUtils.toUpperCase4Index(model.getDomainName()));
        value.put("tableName", model.getTableName());
        model.getColumns().sort(Comparator.comparing(ModelColumn::getSort));
        value.put("columns", model.getColumns());
    }

}
